import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response } from 'express';

@Injectable()
export class AppMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: () => void) {
    console.group('AppMiddleware in');
    console.log('in req', req.baseUrl);
    console.log('in res', JSON.stringify(res.getHeaders()));
    console.groupEnd();
    const start = performance.now();
    res.on('finish', () =>
      console.log('AppMiddleware run time,', performance.now() - start),
    );
    next();
  }
}
